home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / textra16.lha / Textra116 / Scripts / C_Scripts / MarkCFuncs.textra < prev    next >
Encoding:
Text File  |  1994-05-15  |  3.1 KB  |  118 lines

  1.     /*******************************************************************
  2.      *      TEXTRA-AREXX script -- Mike Haas, 1993, Public Domain      *
  3.      *                                                                 *
  4.      *      For use with TEXTRA, the GUI-based Amiga Text Editor.      *
  5.      *                                                                 *
  6.      *  If you enhance or write your own Textra scripts, please send   *
  7.      *   to me... especially if you want them added to the package.    *
  8.      *******************************************************************/
  9.  
  10. /*
  11. **             MarkCFuncs.textra
  12. **
  13. ** This script is handy for C programmers. 
  14. ** It requires version 1.15, rexx level 7, of Textra.
  15. **
  16. ** It will find, highlight and mark all c function declarations in
  17. ** a file.
  18. **
  19. ** It will think there is a declaration if there is at least a '('
  20. ** char on the line AND the text is not indented at all (begins
  21. ** in the first column).  It also checks that there is a '{' character
  22. ** within the next 10 lines.  (vary the MAX_HEADER_LINES value
  23. ** to increase this.  10 lines SHOULD suffice for the huge majority
  24. ** of functions).  If these conditions are met, the word
  25. ** occurring before the '(' character in MARKed as itself().
  26. **
  27. ** This approach is not foolproof, but it will
  28. ** mark the functions in most of the C code I've ever seen to
  29. ** a high degree of accuracy.  The only mistakes I've seen it
  30. ** make is to occasionally MARK something that wasn't a
  31. ** function, such as part of a comment line that has a set of
  32. ** parenthesis in it.
  33. **
  34. ** Especially useful when assigned to a Textra Function
  35. ** key or CTRL-key macro.
  36. **
  37. ** Mike Haas, Nov 8, 1993
  38. **
  39. ** This program is hereby placed in the public domain.
  40. **
  41. */
  42.  
  43. options results
  44.  
  45. /*check Textra version, must be rexx level 7 at least for MARKSELECT */
  46. rex = 0; result = "NOTSUPPORTED"
  47. address 'TEXTRA' 'textraversion'
  48. parse var result maj min rex
  49. if (result == "NOTSUPPORTED") | (rex < 7) then do
  50.         address 'TEXTRA' 'notify "This version of Textra cannot run this script."'
  51.         exit
  52. end
  53.  
  54. /*save hopselect state*/
  55. prefs AlphanumericHops read; hss = result
  56. prefs AlphanumericHops ON
  57.  
  58. MAX_HEADER_LINES = 10
  59.  
  60. done = 0
  61.  
  62. gotoxy 0 0
  63.  
  64. do while (done == 0)
  65.  
  66.     checkcancel
  67.     if (result == CANCEL) then do
  68.         prefs AlphanumericHops hss        /*restore saved state*/
  69.         exit
  70.     end
  71.     
  72.     find "("
  73.     if result == "OK" then  do
  74.  
  75.         get select position
  76.         parse var result stx' 'sty' 'enx' 'eny
  77.         
  78.         gotoxy 0 sty
  79.         get cursor char
  80.         if ((result ~= ' ') & (result ~= '    '/* tab */) & (result ~= '#')) then do
  81.         
  82.             isfunc = 0
  83.             find "{"
  84.             if (result == "OK") then  do
  85.                 get select position; parse var result bstx bsty zx zy
  86.                     if ((sty+MAX_HEADER_LINES) > bsty) then
  87.                         isfunc = 1
  88.             end
  89.             
  90.             if (isfunc == 1) then do
  91.                 gotoxy stx+1 sty
  92.                 hopselect prev word
  93.                 get select text; parse var result zero' 'thename
  94.                 thename = thename"()"
  95.                 markselect thename
  96.             
  97.                 /*
  98.                    Uncomment the next line if you want this script
  99.                    to exit after finding and marking one function.
  100.                 */
  101.             
  102.                 /* done = 1 */
  103.                 
  104.             end
  105.         end
  106.         
  107.         gotoxy 0 sty+1
  108.     
  109.     end
  110.     else
  111.         done = 1
  112.     
  113. end
  114.  
  115. /*restore saved state*/    
  116. prefs AlphanumericHops hss
  117.  
  118.